<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <title>Chat</title>
    <link rel="icon" href="icon/chat.ico">
    <link rel="stylesheet" href="style/chat-style.css">
    <link rel="stylesheet" href="chat-icon/style.css">
    <!--[if lt IE 9 ]>
    <script src="js/html5shiv.min.js"></script>
    <![endif]-->
    <script src="js/lib-flexible.js"></script>
    <style>
        .logo { display: block; margin: 10vh 0; font-size: 16vh; text-align: center; color: #333333; }
        .login { display: block; margin: 10vh auto; width: 60%; }
        .login > input { margin-bottom: 14px; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; }
        .login > p { margin-top: 14px; color: red; text-align: center; }
        .login > input, .login > button { width: 100%; }
        .input-error { border-color: red; }

        .user { padding: 1em; text-align: center; }
        .user img {
            display: block;
            margin: 0 auto;
            width: 6em;
            height: 6em;
            -webkit-border-radius: 3em;
            -moz-border-radius: 3em;
            border-radius: 3em;
        }
        .user p { line-height: 1; margin-top: 10px; }
        .menu {
            position: relative;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
            display: block;
            margin: 10px 0;
            padding: 10px 1em;
            font-size: 14px;
            line-height: 20px;
            vertical-align: 14px;
            background: #ffffff;
        }
        .menu [class*="chat-icon-"] { line-height: 20px; vertical-align: middle; }
        .menu [class*="chat-icon-"]:first-child { margin-right: 1em }
    </style>
</head>
<body>
<div id="app" class="chat-wrap bg-grey" v-cloak>
    <div v-if="!login" class="chat-content bg-grey animated animated-loginPageIn">
        <div class="chat-body">
            <div class="logo"><span class="chat-icon-castle"></span></div>
            <div class="login">
                <input v-model="email" @input="checkEmail" type="email" placeholder="邮箱">
                <input v-model="password" @input="checkPassword" type="password" placeholder="密码">
                <button @click="loginSubmit" type="submit" class="chat-btn">登录</button>
                <p v-html="msg_login"></p>
            </div>
        </div>
    </div>

    <div v-else class="chat-content box-shadow bg-grey" :class="{'animated animated-pageIn': login}">
        <header><button onclick="history.go(-1)" class="chat-header-btn__left chat-icon-turn-left"></button>个人中心</header>
        <div class="chat-body">
            <div class="user bg-theme box-shadow">
                <img src="" :src="user.image" alt="头像">
                <p>{{ user.name }}</p>
                <p>{{ user.email }}</p>
            </div>
            <a v-for="i in menu" :href="i.url" class="menu clear-after">
                <span class="left" :class="i.icon"></span>{{ i.text }}
                <span class="right chat-icon-turn-right color-lightest"></span>
            </a>
        </div>
    </div>
</div>
<script src="js/jquery-1.11.3.min.js"></script>
<script src="js/vue.min.js"></script>
<script>
    var vm = new Vue({
        el: '#app',
        data: {
            login: false,
            email: 'lotency@qq.com',
            password: 'chat124',
            msg_login: '',
            user: {
                name: '络绎不绝',
                email: 'lock@qq.com',
                image: 'chat.ico'
            },
            menu: [
                { url: 'chat_group.html', icon: 'chat-icon-user-group', text: '聊天室'},
                { url: 'chat_single.html', icon: 'chat-icon-user-single', text: '对话室'},
                { url: 'address_book.html', icon: 'chat-icon-address_book', text: '通讯录'},
                { url: 'javascript:', icon: 'chat-icon-setting', text: '个人设置'},
                { url: 'javascript:vm.logout();', icon: 'chat-icon-power', text: '退出'}
            ]
        },
        methods: {
            checkEmail: function () {
                var reg_email = new RegExp('^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$');
                if (!reg_email .test(this.email)) {
                    this.msg_login = '请输入有效的邮箱！';
                    return false;
                } else {
                    this.msg_login = '';
                    return true;
                }
            },
            checkPassword: function () {
                var reg_password = new RegExp('^[a-zA-Z0-9_.-]{6,21}$');
                if (!reg_password .test(this.password)) {
                    this.msg_login = '请输入正确格式的密码！';
                    return false;
                } else {
                    this.msg_login = '';
                    return true;
                }
            },
            loginSubmit: function () {
                if (this.checkEmail() && this.checkPassword()) {
                    this.msg_login = '';
                    this.login = true;
                    sessionStorage.setItem('login', this.login);
                }
            },
            logout: function () {
                this.login = false;
                sessionStorage.removeItem('login')
            }
        },
        mounted: function () {
            this.$nextTick(function () {
                if (sessionStorage.getItem('login')) {
                    this.login = true;
                }
            });
        }
    });
</script>
</body>
</html>
